VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{C932BA88-4374-101B-A56C-00AA003668DC}#1.1#0"; "MSMASK32.OCX"
Begin VB.Form frmHistoriaCliente 
   Caption         =   "ABM Historia Clientes"
   ClientHeight    =   4185
   ClientLeft      =   165
   ClientTop       =   735
   ClientWidth     =   7140
   LinkTopic       =   "Form1"
   ScaleHeight     =   4185
   ScaleWidth      =   7140
   StartUpPosition =   2  'CenterScreen
   Begin VB.Frame frmPrincipal 
      Height          =   3540
      Left            =   120
      TabIndex        =   0
      Top             =   480
      Width           =   6915
      Begin VB.TextBox txtDetalle 
         Height          =   1515
         Left            =   1590
         MultiLine       =   -1  'True
         TabIndex        =   3
         Top             =   1800
         Width           =   5055
      End
      Begin VB.ComboBox cboCliente 
         Height          =   315
         Left            =   1590
         Sorted          =   -1  'True
         Style           =   2  'Dropdown List
         TabIndex        =   2
         Top             =   1230
         Width           =   3420
      End
      Begin VB.TextBox txtIdHistoria 
         BackColor       =   &H80000018&
         Enabled         =   0   'False
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000000&
         Height          =   315
         Left            =   1590
         Locked          =   -1  'True
         TabIndex        =   1
         Top             =   360
         Width           =   945
      End
      Begin MSMask.MaskEdBox txtFecha 
         Height          =   315
         Left            =   1590
         TabIndex        =   9
         Top             =   780
         Width           =   1155
         _ExtentX        =   2037
         _ExtentY        =   556
         _Version        =   393216
         BackColor       =   16777215
         MaxLength       =   10
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Mask            =   "##/##/####"
         PromptChar      =   "_"
      End
      Begin VB.Label lblFecha 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "Fecha:"
         Height          =   195
         Left            =   990
         TabIndex        =   8
         Top             =   840
         Width           =   495
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         Caption         =   "Id. Historia:"
         Height          =   195
         Left            =   720
         TabIndex        =   6
         Top             =   480
         Width           =   795
      End
      Begin VB.Label lblTamanio 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "Detalle:"
         Height          =   195
         Left            =   1005
         TabIndex        =   5
         Top             =   1800
         Width           =   540
      End
      Begin VB.Label lblNombre 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "Cliente:"
         Height          =   195
         Left            =   1020
         TabIndex        =   4
         Top             =   1280
         Width           =   525
      End
   End
   Begin MSComctlLib.Toolbar tbrPrincipal 
      Align           =   1  'Align Top
      Height          =   420
      Left            =   0
      TabIndex        =   7
      Top             =   0
      Width           =   7140
      _ExtentX        =   12594
      _ExtentY        =   741
      ButtonWidth     =   609
      ButtonHeight    =   582
      Appearance      =   1
      _Version        =   393216
      BeginProperty Buttons {66833FE8-8583-11D1-B16A-00C0F0283628} 
         NumButtons      =   7
         BeginProperty Button1 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "sbtAgr"
            Object.ToolTipText     =   "Agregar"
            ImageIndex      =   1
         EndProperty
         BeginProperty Button2 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "sbtMod"
            Object.ToolTipText     =   "Modificar"
            ImageIndex      =   2
         EndProperty
         BeginProperty Button3 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "sbtBus"
            Object.ToolTipText     =   "Buscar"
            ImageIndex      =   3
         EndProperty
         BeginProperty Button4 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "sbtGra"
            Object.ToolTipText     =   "Grabar"
            ImageIndex      =   4
         EndProperty
         BeginProperty Button5 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "sbtCan"
            Object.ToolTipText     =   "Cancelar"
            ImageIndex      =   5
         EndProperty
         BeginProperty Button6 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "sbtBor"
            Object.ToolTipText     =   "Borrar"
            ImageIndex      =   6
         EndProperty
         BeginProperty Button7 {66833FEA-8583-11D1-B16A-00C0F0283628} 
            Key             =   "sbtImp"
            Object.ToolTipText     =   "Imprimir"
            ImageIndex      =   7
         EndProperty
      EndProperty
   End
   Begin VB.Menu menAct 
      Caption         =   "Actividades"
      Begin VB.Menu menAgr 
         Caption         =   "Agregar"
         Shortcut        =   ^A
      End
      Begin VB.Menu menMod 
         Caption         =   "Modificar"
         Shortcut        =   ^M
      End
      Begin VB.Menu menBus 
         Caption         =   "Buscar"
         Shortcut        =   ^B
      End
      Begin VB.Menu menGra 
         Caption         =   "Grabar"
         Shortcut        =   ^G
      End
      Begin VB.Menu menCan 
         Caption         =   "Cancelar"
         Shortcut        =   ^Z
      End
      Begin VB.Menu menBor 
         Caption         =   "Borrar"
         Shortcut        =   ^D
      End
   End
End
Attribute VB_Name = "frmHistoriaCliente"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public exHistoria As Long 'distinto de cero modifica
Public exIdCliente As Long

Private Estado As Integer
Private Enum Estados
        eEsperarOperacion = 0
        eCargar
        eModificar
        eConsultar
        eBorrar
End Enum

Private Sub Refrescar_Formulario(Estado As Integer)
    
    menAgr.Enabled = False
    menMod.Enabled = False
    menBus.Enabled = False
    menGra.Enabled = False
    menCan.Enabled = False
    menBor.Enabled = False
    With tbrPrincipal
        .Buttons(1).Enabled = False
        .Buttons(2).Enabled = False
        .Buttons(3).Enabled = False
        .Buttons(4).Enabled = False
        .Buttons(5).Enabled = False
        .Buttons(6).Enabled = False
        .Buttons(7).Enabled = False
    End With
    Select Case Estado
        Case Estados.eEsperarOperacion
            LimpiarFormulario
            
            With frmPrincipal
                .Caption = ""
                .Enabled = False
            End With
            
            menAgr.Enabled = True
            menBus.Enabled = True
          
            With tbrPrincipal
                .Buttons(1).Enabled = True
                .Buttons(3).Enabled = True
                .Buttons(1).ToolTipText = "Nueva Historia Cliente"
            End With
            
        Case Estados.eModificar
            With frmPrincipal
                .Caption = " Modificando "
                .Enabled = True
            End With
            
            menGra.Enabled = True
            menCan.Enabled = True
            menBor.Enabled = True
            
            With tbrPrincipal
                .Buttons(4).Enabled = True
                .Buttons(5).Enabled = True
                .Buttons(6).Enabled = True
            End With
            
        Case Estados.eCargar
            With frmPrincipal
                .Caption = " Agregando "
                .Enabled = True
            End With
            
            menAct.Enabled = True
            menGra.Enabled = True
            menCan.Enabled = True
            
            With tbrPrincipal
                .Buttons(4).Enabled = True
                .Buttons(5).Enabled = True
            End With
            
        Case Estados.eConsultar
            With frmPrincipal
                .Caption = " Consultando "
                .Enabled = False
            End With

            menAgr.Enabled = True
            menBus.Enabled = True

            With tbrPrincipal
                .Buttons(1).Enabled = True
                .Buttons(3).Enabled = True
            End With
            
        Case Estados.eBorrar
            With frmPrincipal
                .Caption = ""
                .Enabled = False
            End With
            
            menGra.Enabled = True
            menCan.Enabled = True
          
            With tbrPrincipal
                .Buttons(4).Enabled = True
                .Buttons(5).Enabled = True
            End With

    End Select

End Sub

Private Sub Form_Load()
        
    FormsReconfig.Load_Reconfig Me
    Cargar_cboCombos
    If exHistoria <> 0 Then
        Estado = Estados.eModificar
        Refrescar_Formulario Estado
        cargarhistoria exHistoria
    ElseIf exIdCliente <> 0 Then
        Estado = Estados.eCargar
        Refrescar_Formulario Estado
        cboCliente.ListIndex = cboListIndex(Me, cboCliente, exIdCliente)
        Me.txtFecha.TEXT = Date
    Else
        Estado = Estados.eEsperarOperacion
        Refrescar_Formulario Estado
    End If

End Sub

Private Sub cargarhistoria(ByVal id As Long)
Dim ohistcliente As New clsHistClientes
Dim i As Long

    ohistcliente.sel_Historia id
    txtIdHistoria.TEXT = ohistcliente.pRS!id_historia
    txtFecha.TEXT = ohistcliente.pRS!fecha
    txtDetalle.TEXT = ohistcliente.pRS!detalle
    For i = 0 To cboCliente.ListCount - 1
        If cboCliente.ItemData(i) = ohistcliente.pRS!id_cliente Then Exit For
    Next
    cboCliente.ListIndex = i

End Sub

Private Sub Cargar_cboCombos()
Dim oCliente As New clsClientes

    oCliente.sel_Clientes
    If (oCliente.pCanReg > 0) Then
        CargarCombo Me.cboCliente, oCliente.pRS, 0, 1, , "<<Sin Cliente>>"
    End If

End Sub

Private Sub menAgr_Click()

    LimpiarFormulario
    Estado = Estados.eCargar
    Refrescar_Formulario Estado

End Sub

Private Sub menBor_Click()
Dim ohistcliente As New clsHistClientes

    On Error GoTo errHandler
    If Trim(Me.txtIdHistoria.TEXT) <> "" Then
        If MsgBox("Esta seguro que desea eliminar la historia seleccionada?", vbYesNo) = vbYes Then
            If ohistcliente.borrar_historia(Val(Trim(Me.txtIdHistoria.TEXT))) Then
                Unload Me
            Else
                MsgBox "Error al intentar eliminar la historia seleccionada."
            End If
        End If
    Else
        MsgBox "Debe seleccionar una historia antes de intentar eliminarla."
    End If
    Exit Sub

errHandler:
    MsgBox "Error no controlado al momento de eliminar una historia de cliente. "
    Resume Next

End Sub

Private Sub menBus_Click()
Dim ohistcliente As New clsHistClientes

    With frmDesdeHasta
        .RangoFecha = True
        .dtDesde = vbEmpty
        .dtHasta = vbEmpty
        .Show vbModal
        If Not .dtDesde = vbEmpty And Not .dtHasta = vbEmpty Then
            ohistcliente.sel_historias .dtDesde, .dtHasta
            If ohistcliente.pCanReg > 0 Then
                Set frmBuscar03.rsSelecc = ohistcliente.pRS
                frmBuscar03.Show vbModal
            Else
                MsgBox "No se pudo recuperar ninguna historia segun los criterios seleccionados. "
            End If
        End If
    End With
    

End Sub

Private Sub menCan_Click()

    Estado = Estados.eEsperarOperacion
    Refrescar_Formulario Estado

End Sub

Private Sub menGra_Click()
Dim exito As Boolean
Dim oCliente As New clsClientes
Dim ohistcliente As New clsHistClientes
Dim strError As String
Dim vIdHistCliente As Long, vIdCliente As Long

    exito = True
    On Error GoTo errHandler
    If validaDatos() Then
        vIdCliente = Me.cboCliente.ItemData(Me.cboCliente.ListIndex)
        If ohistcliente.insertar_historia(vIdCliente, txtFecha, txtDetalle) Then
            vIdHistCliente = ohistcliente.pIdDevuelto
        Else
            exito = False
            strError = "Error al querer insertar la historia del cliente. " & oCliente.pDesError
        End If
        If exito Then
            Me.txtIdHistoria = vIdHistCliente
            'ActualizarVista
            Estado = Estados.eModificar
            Refrescar_Formulario Estado
        Else
            MsgBox strError
        End If
    End If
    Exit Sub

errHandler:
    exito = False
    strError = "Error no controlado al momento de grabar una historia de cliente. "
    Resume Next
End Sub

Private Function validaDatos() As Boolean
Dim exito As Boolean

    exito = True
    If exito And (Not EsFecha(Me.txtFecha) Or Me.txtFecha.FormattedText = "") Then
        exito = False
        MsgBox "Debe ingresar una fecha antes de grabar.", vbInformation
        Me.txtFecha.SetFocus
    End If
    If exito And Me.cboCliente.ListIndex = -1 Then
        exito = False
        MsgBox "Debe seleccionar un cliente antes de grabar.", vbInformation
        Me.cboCliente.SetFocus
    End If
    If exito And Trim(Me.txtDetalle) = "" Then
        exito = False
        MsgBox "Debe ingresar una historia antes de grabar.", vbInformation
        Me.txtDetalle.SetFocus
    End If
    validaDatos = exito

End Function

Private Sub ActualizarVista()
    cboCliente.ListIndex = 0
    Me.txtDetalle = ""
End Sub

Private Sub tbrPrincipal_ButtonClick(ByVal Button As MSComctlLib.Button)
   
    Select Case Button.Key
        Case "sbtAgr"
            menAgr_Click
        Case "sbtMod"
            'menMod_Click
        Case "sbtBus"
            menBus_Click
        Case "sbtGra"
            menGra_Click
        Case "sbtCan"
            menCan_Click
        Case "sbtBor"
            menBor_Click
        Case "sbtImp"
            'menImp_Click
    End Select
    
End Sub

Private Sub LimpiarFormulario()

    LimpiarTXT Me
    Me.cboCliente.ListIndex = 0

End Sub






